using System.Collections;
using System.IO;
using System.Xml;

namespace OracleInternal.ServiceObjects
{
	public class XmlTypeReader : XmlTextReader
	{
		internal Hashtable m_namespaces = new Hashtable();

		private bool m_bGetSchema;

		internal bool m_bHasTargetNamespace;

		internal string m_schemaURL;

		internal string m_schemaXmlns;

		internal const string XMLNSNotation = "xmlns";

		internal const string XSINotation = "xsi";

		internal const string SchemaLocationNotatation = "noNamespaceSchemaLocation";

		internal const string NSSchemaLocationNotatation = "SchemaLocation";

		public Hashtable CollectedNamespaces => m_namespaces;

		public XmlTypeReader(TextReader textReader)
			: base(textReader)
		{
		}

		public XmlTypeReader(Stream clob)
			: base(clob)
		{
		}

		public override bool Read()
		{
			bool result = base.Read();
			if (base.NodeType == XmlNodeType.Element)
			{
				if (!string.IsNullOrEmpty(base.NamespaceURI) && !m_namespaces.ContainsKey(base.Prefix))
				{
					m_namespaces.Add(base.Prefix, base.NamespaceURI);
				}
				if (!m_bGetSchema)
				{
					for (int i = 0; i < base.AttributeCount; i++)
					{
						MoveToAttribute(i);
						if (string.Compare(base.Prefix, "xmlns", ignoreCase: true) == 0)
						{
							if (string.Compare(base.LocalName, "xsi", ignoreCase: true) == 0)
							{
								m_schemaXmlns = base.Value;
							}
						}
						else if (string.Compare(base.Prefix, "xsi", ignoreCase: true) == 0)
						{
							if (string.Compare(base.LocalName, "SchemaLocation", ignoreCase: true) == 0)
							{
								m_bHasTargetNamespace = true;
								m_bGetSchema = true;
								m_schemaURL = base.Value;
							}
							else if (string.Compare(base.LocalName, "noNamespaceSchemaLocation", ignoreCase: true) == 0)
							{
								m_bHasTargetNamespace = false;
								m_bGetSchema = true;
								m_schemaURL = base.Value;
							}
						}
					}
					MoveToElement();
				}
			}
			return result;
		}
	}
}
